<template>
    <div style=" position: relative;"><el-card>
            <template #header>
                <!-- 搜索 -->
                <div>
                    <!-- <el-input style="width: 360px;" v-model="find_data.find" placeholder="请输入模版名称关键字" clearable
                        prefix-icon="Search" /> -->

                    <el-select style="width: 300px;margin-left: 20px;" v-model="find_data.templatesInfoId"
                        placeholder="请选择模版名称">
                        <el-option v-for="item in findTemplatesInfoNameCombo_list" :key="item.id"
                            :label="item.templates_name" :value="item.id" />

                    </el-select>


                    <el-select style="width: 230px;margin-left: 20px;" v-model="find_data.stationListId"
                        placeholder="请选择站点地址" clearable>
                        <el-option v-for="item in getStationList_Data" :key="item.id" :label="item.stationName"
                            :value="item.id" />
                    </el-select>
                    <el-select @change='seats_change1' style="width: 160px;margin-left: 20px;" v-model="find_data.seats"
                        placeholder="请选择座位数">
                        <el-option v-for="item in seats_list" :key="item.value" :label="item.label"
                            :value="item.value" />

                    </el-select>

                    <el-select @change="carConfigurationType_change1" style="width:350px;margin-left: 20px;"
                        v-model="find_data.carConfigurationType" placeholder="请选择车辆配置">
                        <el-option v-for="item in getCarConfigurationType_list2" :key="item.id"
                            :label="item.val + '(' + item.other + ')'" :value="item.id" />
                    </el-select>
                    <el-button style="margin-left: 20px;height:30px" @click="search_btn" type="primary"
                        icon="Search">搜索</el-button>
                </div>
                <!-- 功能按钮 -->
                <div style="margin-top:10px;">
                    <el-button @click="add_btn" type="primary" icon="SuccessFilled">添加</el-button>
                    <el-button @click="up_btn" type="warning" icon="WarnTriangleFilled">修改</el-button>
                    <el-button @click="del_btn" type="danger" icon="CircleCloseFilled">删除</el-button>
                </div>
            </template>
            <div>
                <el-table border @selection-change="selection_change_btn" height="67vh" ref="multipleTableRef"
                    :data="list_data" style="width: 100%">
                    <el-table-column type="selection" width="35" />
                    <el-table-column label="编号" width="55" fixed type="index" />
                    <template v-for="item in table_data_list_new" :key="item.field">
                        <el-table-column v-if="item.off" :width="item.width" :prop="item.field" :label="item.label">
                            <template v-if="item.field == 'carConfigurationType'" #="{ row, column, $index }">
                                <span>{{ row.carConfigurationType == 'ECONOMICAL' ? '经济型' : row.carConfigurationType ==
                                    'COMFORTABLE' ? '舒适型' : row.carConfigurationType == 'LUXURY' ? '豪华型' :
                                    row.carConfigurationType ==
                                        'BUSINESS_NANNY_CAR' ? '商务保姆车' : row.carConfigurationType ==
                                            'ECONOMICAL_MIDDLE_CAR' ? '经济中巴' : row.carConfigurationType ==
                                                'COMFORTABLE_MIDDLE_CAR' ? '舒适中巴' : row.carConfigurationType ==
                                                    'LUXURY_MIDDLE_CAR' ? ' 豪华中巴' : row.carConfigurationType ==
                                                        'MIDDLE_NANNY_CAR' ? '中巴保姆车' : row.carConfigurationType ==
                                                            'TRAVEL_LARGE_CAR' ? '旅游大巴' : row.carConfigurationType ==
                                                                'LARGE_NANNY_CAR' ? '大巴保姆车' : '暂无'
                                    }}</span>

                            </template>


                        </el-table-column>
                    </template>
                </el-table>
            </div>

            <div style="margin-top:20px">
                <el-pagination @current-change="current_change_btn" @size-change="size_change_btn"
                    v-model:current-page="find_data.page.pageNum" v-model:page-size="find_data.page.pageSize"
                    :page-sizes="[20, 50, 100, 200]" :background="true"
                    layout="prev, pager, next, jumper,->,sizes,total," :total="total" />
            </div>
        </el-card>
    </div>

    <!-- 弹窗 -->
    <div>
        <!-- 表格筛选 -->
        <div style="position: absolute;top:75px;z-index: 2;" :style="icon_off ? 'right:0px;' : 'right:110px;'">
            <el-icon @click="icon_btn" :size="20">
                <Setting />
            </el-icon>
            <div v-show="icon_off"
                style=" position: relative;top:-100px;right:140px;width: 130px;height:430px;background:#fff;overflow: hidden;">
                <div class="cols-set" style="background:#fff;width:90%;height:97%;margin:auto;margin-top:10px;">
                    <div>
                        <el-button-group style="display: flex; ">
                            <el-tooltip effect="dark" placement="bottom">
                                <template #content>注意：拖动下面的项，可以改变表格列的顺序，<br />记得点击保存才会永久生效哦！ </template>
                                <el-button style="width:10px" type="primary" icon="WarningFilled"></el-button>
                            </el-tooltip>
                            <el-button title="重置" type="primary" icon="Refresh" @click="resetTableSet"></el-button>
                            <el-button title="保存" type="primary" icon="Check" @click="saveTableSet"></el-button>
                        </el-button-group>
                        <div ref="sortableContainer" class="col-items" style="height:400px; overflow-y: auto; ">
                            <el-checkbox class="drag_it" @change="checkbox_btn" v-for="item in sortedItems"
                                :key="item.field" v-model="item.off" :label="item.label" border>
                            </el-checkbox>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <!-- 添加修改 -->
        <el-dialog style="margin-top:5vh" v-model="add_off" :title="title" width="65%" :close-on-click-modal='false'>
            <el-form :model="add_data" label-width="140px" label-suffix="：">


                <el-row>
                    <el-col :span="8">
                        <el-form-item label="模版名称" :required="false">
                            <el-select
                                :disabled="title == '修改顺风车价格模板设置' && add_data.templatesInfoId == '1' ? true : false"
                                v-model="add_data.templatesInfoId" placeholder="请选择模版" clearable>
                                <el-option v-for="item in findTemplatesInfoNameCombo_list" :key="item.id"
                                    :label="item.templates_name" :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="区域地址">
                            <el-select v-model="add_data.areaId" placeholder="请选择区域" clearable>
                                <el-option v-for="item in getAreaSetList_list" :key="item.id" :label="item.areaName"
                                    :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="站点地址" :required="false">
                            <el-select multiple collapse-tags collapse-tags-tooltip v-model="add_data.stationListIds"
                                placeholder="请选择站点地址" clearable>
                                <el-option v-for="item in getStationList_Data" :key="item.id" :label="item.stationName"
                                    :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>


                <el-row>
                    <el-col :span="12">
                        <el-form-item label="座位数" :required="false">
                            <!-- <el-input type="number" style="width:220px" v-model="add_data.seats"
                                placeholder="请输入座位数eg:5" clearable>
                                <template #append>座</template>
                            </el-input> -->
                            <el-select @change='seats_change' v-model="add_data.seats" placeholder="请选择座位数">
                                <el-option v-for="item in seats_list" :key="item.value" :label="item.label"
                                    :value="item.value" />

                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="车辆配置" :required="true">
                            <el-select style="width:350px" @change='carConfigurationType_change'
                                v-model="add_data.carConfigurationType" placeholder="请选择车辆配置">
                                <el-option v-for="item in getCarConfigurationType_list" :key="item.id"
                                    :label="item.val + '(' + item.other + ')'" :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>


                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="起步价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.basePrice"
                                placeholder="请输入起步价 eg:200" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="优惠价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.basePreferentialPrice"
                                placeholder="请输入优惠价 eg:200" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="包含公里数" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.baseKilo"
                                placeholder="请输入起步价包含公里数 eg:30" clearable>
                                <template #append>公里</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="12">
                        <el-form-item label="超起步公里数单价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.moreBaseKiloPrice"
                                placeholder="请输入超起步公里数单价eg:30" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="超起步公里数" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.moreBaseKilo"
                                placeholder="请输入超起步公里数eg:200" clearable>
                                <template #append>公里</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="超长公里数单价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.moreLongBaseKiloPrice"
                                placeholder="请输入超长公里数单价eg:200" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="超长公里数" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.moreLongBaseKilo"
                                placeholder="请输入超长公里数eg:300" clearable>
                                <template #append>公里</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="最长公里数单价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.longestKiloPrice"
                                placeholder="请输入最长公里数单价eg:200" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="加点费单价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.singlePointPrice"
                                placeholder="请输入加点费单价eg:30" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>

                </el-row>



                <el-row>
                    <el-col :span="8">
                        <el-form-item label="夜班1开始时间" :required="false">
                            <el-time-picker format="HH:mm" value-format="HH:mm" v-model="add_data.nightOneStime"
                                :picker-options="{
                                    selectableRange: '00:00:00 - 23:59:59'
                                }" placeholder="选择夜班1开始时间" style="width: 200px;">
                            </el-time-picker>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="夜班1结束时间" :required="false">
                            <el-time-picker format="HH:mm" value-format="HH:mm" v-model="add_data.nightOneEtime"
                                :picker-options="{
                                    selectableRange: '00:00:00 - 23:59:59'
                                }" placeholder="选择夜班1结束时间" style="width: 200px;">
                            </el-time-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="夜班1加价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.nightOnePrice"
                                placeholder="请输入夜班1加价" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="夜班2开始时间" :required="false">
                            <el-time-picker format="HH:mm" value-format="HH:mm" v-model="add_data.nightTwoStime"
                                :picker-options="{
                                    selectableRange: '00:00:00 - 23:59:59'
                                }" placeholder="选择夜班2开始时间" style="width: 200px;">
                            </el-time-picker>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="夜班2结束时间" :required="false">
                            <el-time-picker format="HH:mm" value-format="HH:mm" v-model="add_data.nightTwoEtime"
                                :picker-options="{
                                    selectableRange: '00:00:00 - 23:59:59'
                                }" placeholder="选择夜班2结束时间" style="width: 200px;">
                            </el-time-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="夜班2加价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.nightTwoPrice"
                                placeholder="请输入夜班2加价" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div style="margin-left:50vw;margin-top:8px;display:flex">
                <el-button v-if="title != '修改顺风车价格模板设置'" @click="ok_btn(1)" type="warning">保存并继续</el-button>
                <el-button @click="ok_btn(2)" type="primary">确认提交</el-button>
            </div>

        </el-dialog>
    </div>
</template>

<script setup>
import Sortable from 'sortablejs';
import { ref, reactive, onMounted, computed } from 'vue'
import CircularJSON from 'circular-json'
import {
    getSfcPriceTemplatesPages, getAreaSetList, getStationListPages, findTemplatesInfoNameCombo, getCarConfigurationType,
    adupSfcPriceTemplates, delSfcPriceTemplates, adupPrivateSet, getPrivateSetList
} from '@/api/system_management.js'
import { ElMessage, ElLoading, ElMessageBox } from 'element-plus'
onMounted(async () => {


    getPrivateSetList({
        find: '顺风车价格模板设置',
        page: {
            pageNum: 1,
            pageSize: 999,
        },
    }).then(res => {
        if (res.data.list[0]) {
            table_data_list_new.value = JSON.parse(res.data.list[res.data.list.length - 1].dat)
        } else {
            table_data_list_new.value = table_data_list
        }
    })


    Sortable.create(sortableContainer.value, {
        draggable: '.drag_it',
        ghostClass: 'sortable-ghost',
        onEnd: evt => {
            const targetRow = table_data_list_new.value.splice(evt.oldIndex, 1)[0];
            table_data_list_new.value.splice(evt.newIndex, 0, targetRow);

            // 重新赋值给列数组
            // let cols = that.U.scopy(that.fields);
            // let list = cols.filter(it => { return it.show; });
            // that.$emit('saveSet', {dgName: that.dgName, cols: list});
        }
    })


    await list_api()

    getAreaSetList({
        page: {
            pageNum: 1,
            pageSize: 999,
        },
        find: '',
    }).then(res => {
        getAreaSetList_list.value = res.data.list
    })

    getStationListPages({
        page: {
            pageNum: 1,
            pageSize: 999,
        },
        stationTypes: ['TRAIN', 'AIRPORT', 'BUS'],
    }).then(res => {
        if (res.code == 1) {
            getStationList_Data.value = res.data.list
        }
    })

    findTemplatesInfoNameCombo({
        page: {
            pageNum: 1,
            pageSize: 999,
        },
        find: '',
    }).then(res => {
        findTemplatesInfoNameCombo_list.value = res.data.list
    })


})
const seats_list = ref([
    {
        value: 5,
        label: '5座'
    },
    {
        value: 7,
        label: '7座'
    },
    {
        value: 9,
        label: '9座'
    },
    {
        value: 12,
        label: '12座'
    },
    {
        value: 14,
        label: '14座'
    },
    {
        value: 17,
        label: '17座'
    },

    {
        value: 23,
        label: '23座'
    },
    {
        value: 30,
        label: '30座'
    },
    {
        value: 39,
        label: '39座'
    },
    {
        value: 49,
        label: '49座'
    },
    {
        value: 55,
        label: '55座'
    },
])

const seats_change = () => {

    add_data.carConfigurationType = ''
    let luser = JSON.parse(localStorage.getItem("luser"))
    let luser_companyNum = luser.companyNum
    getCarConfigurationType({
        addWay: '0',
        seats: add_data.seats,
        companyNum: luser_companyNum,
    }).then(res => {
        getCarConfigurationType_list.value = res.data
    })
}
const carConfigurationType_change = () => {
    console.log(add_data.carConfigurationType)
    for (let i = 0; i < getCarConfigurationType_list.value.length; i++) {
        if (add_data.carConfigurationType == getCarConfigurationType_list.value[i].id) {
            add_data.carConfigurationSeries = getCarConfigurationType_list.value[i].other
        }
    }
}
const getCarConfigurationType_list2 = ref([])
const seats_change1 = () => {

    find_data.carConfigurationType = ''
    let luser = JSON.parse(localStorage.getItem("luser"))
    let luser_companyNum = luser.companyNum
    getCarConfigurationType({
        addWay: '0',
        seats: find_data.seats,
        companyNum: luser_companyNum,
    }).then(res => {
        getCarConfigurationType_list2.value = res.data
    })
}
const carConfigurationType_change1 = () => {
    for (let i = 0; i < getCarConfigurationType_list2.value.length; i++) {
        if (find_data.carConfigurationType == getCarConfigurationType_list2.value[i].id) {
            find_data.carConfigurationSeries = getCarConfigurationType_list2.value[i].other
        }
    }
}
//#region 表格数据处理
const table_data_list = reactive([
    { label: '模板名称', field: 'templatesInfoId', width: 100, off: true },
    { label: '区域地址', field: 'areaId', width: 100, off: true },
    { label: '站点地址', field: 'stationListId', width: 150, off: true },
    { label: '车辆配置', field: 'carConfigurationType', width: 100, off: true },
    { label: '起步价', field: 'basePrice', width: '', off: true },
    { label: '优惠价', field: 'basePreferentialPrice', width: '', off: true },
    { label: '起步价包含公里数', field: 'baseKilo', width: 145, off: true },

    // { label: '最长公里数', field: 'longestKilo', width: 105, off: true },
    { label: '超起步公里数单价', field: 'moreBaseKiloPrice', width: 145, off: true },
    { label: '超起步公里数', field: 'moreBaseKilo', width: 120, off: true },
    { label: '超长公里数单价', field: 'moreLongBaseKiloPrice', width: 130, off: true },
    { label: '超长公里数', field: 'moreLongBaseKilo', width: 115, off: true },
    { label: '最长公里数单价', field: 'longestKiloPrice', width: 125, off: true },
    { label: '夜班1开始时间', field: 'nightOneStime', width: 120, off: true },
    { label: '夜班1结束时间', field: 'nightOneEtime', width: 120, off: true },
    { label: '夜班1加价', field: 'nightOnePrice', width: 120, off: true },
    { label: '夜班2开始时间', field: 'nightTwoStime', width: 120, off: true },
    { label: '夜班2结束时间', field: 'nightTwoEtime', width: 120, off: true },
    { label: '夜班2加价', field: 'nightTwoPrice', width: 120, off: true },
    { label: '加点费单价', field: 'singlePointPrice', width: 100, off: true },
    { label: '座位数', field: 'seats', width: 80, off: true },
    { label: '添加时间', field: 'addTime', width: 165, off: true },
])

const table_data_list_new = ref([])
const icon_off = ref(false)
// 创建排序容器的引用
const sortableContainer = ref('')

const icon_btn = () => {
    icon_off.value = !icon_off.value
    console.log(sortableContainer.value)

}
const resetTableSet = () => {
    console.log(table_data_list)
    table_data_list_new.value = JSON.parse(JSON.stringify(table_data_list))
    console.log(table_data_list)
    console.log(table_data_list_new.value)
}
const saveTableSet = () => {
    adupPrivateSet({
        dat: JSON.stringify(table_data_list_new.value),
        tbName: '顺风车价格模板设置',
        tbNum: "PriceTemplates",
    }).then(res => {
        if (res.code == 1) {
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
    icon_off.value = false
}

const checkbox_btn = (e, c) => {
    for (let i = 0; i < table_data_list_new.value.length; i++) {
        if (table_data_list_new.value[i].label == c.target._value) {
            table_data_list_new.value[i].off == e

        }

    }

}

const sortedItems = computed(() => {
    return [...table_data_list_new.value].sort((a, b) => a.id - b.id);
})
//#endregion



//#region 分页列表
const list_data = ref([])
const find_data = reactive({
    page: {
        pageNum: 1,
        pageSize: 20,
    },
    areaId: '',
    carConfigurationType: '',
    seats: "",
    stationListId: '',
    templatesInfoId: '',

})
const total = ref(0)

// 分页器一夜显示多少数据页面
const size_change_btn = () => {
    find_data.page.pageNum = 1
    list_api()
}

// 分页器跳转页面
const current_change_btn = () => {
    list_api()
}

const list_api = () => {

    getSfcPriceTemplatesPages(find_data).then(res => {
        list_data.value = res.data.list
        total.value = res.data.total
    })
}
//#endregion

//#region 添加
const add_off = ref(false)
const findTemplatesInfoNameCombo_list = ref([])
const getAreaSetList_list = ref([])
const getStationList_Data = ref([])
const getCarConfigurationType_list = ref([])

const title = ref('添加顺风车价格模板设置')
const add_data = reactive({
    id: "",
    areaId: "",
    baseKilo: "",
    basePrice: "",
    basePreferentialPrice: '',
    carConfigurationType: "",
    longestKilo: "",
    longestKiloPrice: "",
    moreBaseKilo: "",
    moreBaseKiloPrice: "",
    moreLongBaseKilo: "",
    moreLongBaseKiloPrice: "",
    nightOneEtime: "",
    nightOnePrice: "",
    nightOneStime: "",
    nightTwoEtime: "",
    nightTwoPrice: "",
    nightTwoStime: "",
    seats: "",
    singlePointPrice: "",
    stationListIds: "",
    templatesInfoId: "",
    carConfigurationSeries: '',
})


const add_btn = () => {

    title.value = '添加顺风车价格模板设置'
    add_data.id = ''
    add_data.areaId = ''
    add_data.baseKilo = ''
    add_data.basePrice = ''
    add_data.basePreferentialPrice = ''
    add_data.carConfigurationType = ''
    add_data.longestKilo = ''
    add_data.longestKiloPrice = ''
    add_data.moreBaseKilo = ''
    add_data.moreBaseKiloPrice = ''
    add_data.moreLongBaseKilo = ''
    add_data.moreLongBaseKiloPrice = ''
    add_data.nightOneEtime = ''
    add_data.nightOnePrice = ''
    add_data.nightOneStime = ''
    add_data.nightTwoEtime = ''
    add_data.nightTwoPrice = ''
    add_data.nightTwoStime = ''
    add_data.seats = ''
    add_data.singlePointPrice = ''
    add_data.stationListIds = ''
    add_data.templatesInfoId = ''
    add_data.carConfigurationSeries = ''


    add_off.value = true

}


//#endregion

//#region 表格选择
const table_list = ref([])
const selection_change_btn = (e) => {
    table_list.value = e
    console.log(e)
}
//#endregion
//#region 修改
const up_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }


    title.value = '修改顺风车价格模板设置'

    add_data.id = table_list.value[0].id

    for (let i = 0; i < getAreaSetList_list.value.length; i++) {
        if (getAreaSetList_list.value[i].areaName == table_list.value[0].areaId) {
            add_data.areaId = getAreaSetList_list.value[i].id
        }
    }
    for (let i = 0; i < findTemplatesInfoNameCombo_list.value.length; i++) {
        if (findTemplatesInfoNameCombo_list.value[i].templates_name == table_list.value[0].templatesInfoId) {
            add_data.templatesInfoId = findTemplatesInfoNameCombo_list.value[i].id
        }
    }
    for (let i = 0; i < getStationList_Data.value.length; i++) {
        if (getStationList_Data.value[i].stationName == table_list.value[0].stationListId) {
            add_data.stationListIds = [getStationList_Data.value[i].id]
        }
    }

    add_data.carConfigurationType = table_list.value[0].carConfigurationType

    add_data.baseKilo = table_list.value[0].baseKilo
    add_data.basePrice = table_list.value[0].basePrice
    add_data.basePreferentialPrice = table_list.value[0].basePreferentialPrice
    add_data.longestKilo = table_list.value[0].longestKilo
    add_data.longestKiloPrice = table_list.value[0].longestKiloPrice
    add_data.moreBaseKilo = table_list.value[0].moreBaseKilo
    add_data.moreBaseKiloPrice = table_list.value[0].moreBaseKiloPrice
    add_data.moreLongBaseKilo = table_list.value[0].moreLongBaseKilo
    add_data.moreLongBaseKiloPrice = table_list.value[0].moreLongBaseKiloPrice
    add_data.nightOneEtime = table_list.value[0].nightOneEtime
    add_data.nightOnePrice = table_list.value[0].nightOnePrice
    add_data.nightOneStime = table_list.value[0].nightOneStime
    add_data.nightTwoEtime = table_list.value[0].nightTwoEtime
    add_data.nightTwoPrice = table_list.value[0].nightTwoPrice
    add_data.nightTwoStime = table_list.value[0].nightTwoStime
    add_data.seats = table_list.value[0].seats
    add_data.singlePointPrice = table_list.value[0].singlePointPrice
    add_data.carConfigurationSeries = table_list.value[0].carConfigurationSeries
    let luser = JSON.parse(localStorage.getItem("luser"))
    let luser_companyNum = luser.companyNum
    getCarConfigurationType({
        addWay: '0',
        seats: add_data.seats,
        companyNum: luser_companyNum,
    }).then(res => {
        getCarConfigurationType_list.value = res.data
    })
    add_off.value = true
}
//#endregion

// 将时间转换为分钟数
const convertToMinutes = (timeStr) => {
    const [hours, minutes] = timeStr.split(':').map(Number);
    return hours * 60 + minutes;
}

// 提交
const ok_btn = (e) => {
    // 定义要比较的两个时间
    //let time1 = add_data.nightOneEtime
    //let time2 = add_data.nightTwoStime
    // 转换时间为分钟数
    //let time1Minutes = convertToMinutes(time1);
    //let time2Minutes = convertToMinutes(time2);
    // 比较时间大小
    //if (time2Minutes < time1Minutes) {
    //return ElMessage({
    //message: '夜班2开始时间不能小于夜班1结束时间',
    //type: 'warning',
    //})
    //}
    if (!add_data.carConfigurationType) {
        return ElMessage({
            message: '请选择车辆配置',
            type: 'warning',
        })
    }


    adupSfcPriceTemplates(add_data).then(res => {
        if (res.code == 1) {
            list_api()
            if (e == 2 || title.value == '修改顺风车价格模板设置') {
                add_off.value = false
            }
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}


//#region 删除
const del_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }

    ElMessageBox.confirm(
        '是否确认删除客户?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            if (table_list.value[0].templatesInfoId == '基础模版') {
                return ElMessage({
                    message: '基础模版不能删除，只能修改',
                    type: 'warning',
                })
            } else {
                delSfcPriceTemplates({
                    ids: [table_list.value[0].id]
                }).then(res => {
                    if (res.code == 1) {
                        list_api()
                        return ElMessage({
                            message: res.msg,
                            type: 'success',
                        })
                    } else {
                        return ElMessage({
                            message: res.msg,
                            type: 'warning',
                        })
                    }
                })
            }



        })
        .catch((e) => {
            if (e == 'cancel') {
                ElMessage({
                    type: 'warning',
                    message: '取消删除成功',
                })
            }

        })

}
//#endregion

//#region 搜索
const search_btn = () => {
   
    list_api()
}
//#endregion
</script>

<style scoped lang='scss'></style>
<style>
.col-items::-webkit-scrollbar {
    width: 5px !important;
}

.col-items>label {
    margin-left: 0px !important;
    margin-top: 5px;
    width: 100%;
}

.el-table .el-table__cell {
    padding: 0px !important;
}
</style>
